<template>
  <div class="app-container">
    <el-form :model="queryParams"
             ref="queryForm"
             :inline="true"
             v-show="showSearch"
             label-width="68px"
    >
      <el-form-item label="设备id"
                    prop="nodeId"
      >
        <el-input v-model="queryParams.id"
                  placeholder="请输入设备id"
                  clearable
                  size="small"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备名称"
                    prop="name"
      >
        <el-input v-model="queryParams.name"
                  placeholder="请输入设备名称	"
                  clearable
                  size="small"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="dtuId"
                    prop="dtuId"
      >
        <el-input v-model="queryParams.dtuId"
                  placeholder="请输入dtuId"
                  clearable
                  size="small"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备状态"
                    prop="status"
      >
        <el-select v-model="queryParams.type"
                   placeholder="设备类型"
                   size="small"
                   clearable
                   @keyup.enter.native="handleQuery"
        >

          <el-option
            v-for="type in deviceTypeOption"
            :key="'deviceTypeOption'+type.dictValue"
            :label="type.dictLabel"
            :value="type.dictValue"
          ></el-option>

        </el-select>
      </el-form-item>
      <el-form-item label="设备状态"
                    prop="status"
      >
        <el-select v-model="queryParams.status"
                   placeholder="设备状态"
                   size="small"
                   clearable
                   @keyup.enter.native="handleQuery"
        >

          <el-option label="启用"
                     value="1"
          ></el-option>
          <el-option label="禁用"
                     value="0"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
                   icon="el-icon-search"
                   size="mini"
                   @click="handleQuery"
        >搜索
        </el-button>
        <el-button icon="el-icon-refresh"
                   size="mini"
                   @click="resetQuery"
        >重置
        </el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10"
            class="mb8"
    >
      <el-col :span="1.5">
        <el-button type="primary"
                   plain
                   icon="el-icon-plus"
                   size="mini"
                   @click="handleAdd"
                   v-hasPermi="['system:appsecret:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success"
                   plain
                   icon="el-icon-edit"
                   size="mini"
                   :disabled="single"
                   @click="handleUpdate"
                   v-hasPermi="['system:appsecret:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger"
                   plain
                   icon="el-icon-delete"
                   size="mini"
                   :disabled="multiple"
                   @click="handleDelete"
                   v-hasPermi="['system:appsecret:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning"
                   plain
                   icon="el-icon-download"
                   size="mini"
                   @click="handleExport"
                   v-hasPermi="['system:appsecret:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch"
                     @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading"
              :data="appsecretList"
              @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection"
                       width="55"
                       align="center"
      />
      <el-table-column label="设备地址"
                       align="center"
                       prop="addr"
                       v-if="false"
      />

      <el-table-column label="品牌"
                       align="center"
                       prop="deviceBrand.brandName"
      />
      <el-table-column label="DtuId"
                       align="center"
                       prop="dtuId"
      />
      <el-table-column label="设备名称"
                       align="center"
                       prop="name"
      />
      <el-table-column label="设备ID"
                       align="center"
                       prop="id"
      />
      <el-table-column label="设备状态"
                       align="center"
                       prop="status"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0">关闭</span>
          <span v-if="scope.row.status == 1">开启</span>

        </template>
      </el-table-column>
      <el-table-column label="设备类型"
                       align="center"
                       prop="status"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type == 1">电表</span>
          <span v-if="scope.row.type == 2">水表</span>

        </template>
      </el-table-column>
      <el-table-column label="下发key"
                       align="center"
                       prop="valveKey"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type == 1">{{ scope.row.valveKey ? scope.row.valveKey : '无' }}</span>
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="columnProp"
        label="开关闸"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.brakeStatus"
            :active-value="1"
            :inactive-value="0"
            @change="switchGate($event,scope.row)"
          >
          </el-switch>
        </template>

      </el-table-column>

      <!-- <el-table-column label="用户地址" align="center" prop="addr"/> -->
      <el-table-column label="操作"
                       align="center"
                       class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="handleUpdate(scope.row)"
                     v-hasPermi="['system:appsecret:edit']"
          >修改
          </el-button>
          <el-button size="mini"
                     type="text"
                     icon="el-icon-delete"
                     @click="handleDelete(scope.row)"
                     v-hasPermi="['system:appsecret:remove']"
          >删除
          </el-button>
          <el-button size="mini"
                     type="text"
                     icon="el-icon-zoom-in"
                     @click="handleWatch(scope.row)"
                     v-hasPermi="['system:info:remove']"
          >查看
          </el-button>
          <el-button size="mini"
                     type="text"
                     v-if="scope.row.type == 1"
                     icon="el-icon-edit"
                     @click="meterReadingRecording(scope.row)"
                     v-hasPermi="['system:info:remove']"
          >抄表
          </el-button>
          <el-button size="mini"
                     type="text"
                     v-if="scope.row.type == 1"
                     icon="el-icon-edit"
                     @click="recording(scope.row)"
                     v-hasPermi="['system:info:remove']"
          >抄表记录
          </el-button>
          <el-button size="mini"
                     type="text"
                     v-if="scope.row.type == 1"
                     icon="el-icon-edit"
                     @click="brakeRecord(scope.row)"
                     v-hasPermi="['system:info:remove']"
          >合闸记录
          </el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title"
               :visible.sync="open"
               width="500px"
               :close="closeForm"
               append-to-body
    >
      <el-form ref="form"
               :model="form"
               :rules="rules"
               label-width="100px"
      >
        <el-form-item label="设备地址	"
                      prop="addr"
        >
          <el-input v-model="form.addr"
                    placeholder="请输入设备地址"
          />
        </el-form-item>
        <el-form-item label="品牌"
        >
          <el-select v-model="form.brandId"
                     :disabled="true"
                     v-show="form.brandId"
          >
            <el-option
              v-for="(item,index) in brandOption"
              :key="item.label+''+index"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-button type="text" @click="getBrand" style="margin-left: 20px;">选择品牌</el-button>
        </el-form-item>
        <el-form-item label="DTU"
        >
          <el-select v-model="form.dtuId"
                     :disabled="true"
                     v-if="form.dtuId"
          >
            <el-option
              :label="DtuOption.label"
              :value="DtuOption.value"
            >
            </el-option>
          </el-select>
          <el-button type="text" @click="getDtu" style="margin-left: 20px;">选择DTU</el-button>
        </el-form-item>
        <!--     <el-form-item label="已调用次数" prop="transferCount">
          <el-input v-model="form.transferCount" placeholder="请输入已调用次数"/>
        </el-form-item> -->
        <el-form-item label="设备名称	"
                      prop="name"
        >
          <el-input v-model="form.name"
                    placeholder="请输入设备名称"
          />
        </el-form-item>
        <el-form-item label="nodeId	"
                      prop="nodeId"
        >
          <el-input v-model="form.nodeId"
                    placeholder="请输入nodeId"
          />
        </el-form-item>
        <el-form-item label="通讯地址	"
                      prop="slaves"
        >
          <el-input v-model="form.slaves"
                    placeholder="请输入通讯地址	"
          />
        </el-form-item>
        <el-form-item label="设备状态	" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio v-model="form.status"
                      :label="0"
            >禁用
            </el-radio>
            <el-radio v-model="form.status"
                      :label="1"
            >启用
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="设备类型	" prop="type">
          <el-radio-group v-model="form.type	">
            <el-radio v-model="form.type"
                      :label="1"
            >电表
            </el-radio>
            <el-radio v-model="form.type"
                      :label="2"
            >水表
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="下发key"
                      v-if="form.type ==1"
                      v-model="form.type"
                      prop="valveKey	"
        >
          <el-input v-model="form.valveKey	"
                    placeholder="请输入下发key"
          />
        </el-form-item>
      </el-form>
      <div slot="footer"
           class="dialog-footer"
      >
        <el-button type="primary"
                   @click="submitForm"
        >确 定
        </el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看表单 -->
    <el-dialog :title="title"
               :visible.sync="openView"
               width="700px"

               append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        label-width="120px"
        size="mini"
        align-item="left"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备地址">{{ form.addr }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="品牌id">{{ form.brandId }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="DtuId">{{ form.dtuId }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备id">{{ form.nodeId }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备名称">{{ form.name }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="通讯地址">{{ form.slaves }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="锁状态">{{ form.status == 0 ? '关闭' : '开启' }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备类型">{{ form.type == 1 ? '电表' : '水表' }}</el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.type == 1">
            <el-form-item label="下发key	">{{ form.valveKey }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer"
           class="dialog-footer"
      >
        <el-button @click="openView = false">关 闭</el-button>
      </div>
    </el-dialog>
    <!--    品牌列表弹窗-->
    <el-dialog
      title="品牌列表"
      :visible.sync="brandOpen"
      width="30%"
      style="height: 1000px;"

    >

      <el-table
        v-if="brandList.rows"
        :data="brandList.rows"
        highlight-current-row
        @current-change="brandCurrent"
        style="width: 100%"
      >
        <el-table-column
          prop="brandName"
          label="品牌名称	"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="content"
          label="品牌内容	"
          width="180"
        >
        </el-table-column>
        <el-table-column
          label="品牌图片"
        >
          <template slot-scope="scope">
            <el-image
              style="width: 100px; height: 100px"
              :preview-src-list="[scope.row.pic]"
              :src="scope.row.pic"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column label="品牌类型" align="center" prop="type">
          <template slot-scope="scope">
            <span v-if="scope.row.type == 1">门锁</span>
            <span v-if="scope.row.type == 2">电表</span>
            <span v-if="scope.row.type == 3">水表</span>
            <span v-if="scope.row.type == 4">Dtu</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-if="brandList.total>0"
        :total="brandList.total"
        :page.sync="brandQuery.pageNum"
        :limit.sync="brandQuery.pageSize"
        @pagination="getBrand"
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="brandOpen = false">取 消</el-button>
        <el-button type="primary" @click="brandOpen = false">确 定</el-button>
      </span>
    </el-dialog>
    <!--    Dtu列表-->
    <el-dialog
      title="Dtu列表"
      :visible.sync="DtuOpen"
      width="30%"
      style="height: 1000px;"
    >
      <el-table
        :data="DtuList.rows"
        highlight-current-row
        @current-change="DtuCurrent"
        style="width: 100%;"
      >
        <el-table-column
          prop="addr"
          label="dtu地址"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="dtu名称"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="dtu名称"
          width="180"
        >
        </el-table-column>
        <el-table-column label="设备状态" align="center" prop="type">
          <template slot-scope="scope">
            <span v-if="scope.row.status == 1">禁用</span>
            <span v-if="scope.row.status == 2">启用中</span>
          </template>
        </el-table-column>
        <el-table-column label="类型" align="center" prop="type">
          <template slot-scope="scope">
            <span v-if="scope.row.type == 1">水</span>
            <span v-if="scope.row.type == 2">电</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-if="DtuList.total > 0"
        :total="DtuList.total"
        :page.sync="DtuQuery.pageNum"
        :limit.sync="DtuQuery.pageSize"
        @pagination="getDtu"
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="DtuOpen = false">取 消</el-button>
        <el-button type="primary" @click="DtuOpen = false">确 定</el-button>
      </span>
    </el-dialog>
    <!--    抄表记录-->
    <el-dialog
      title="抄表记录"
      :visible.sync="meterRecordingDialog"
      width="50%"
    >
      <div>
        <el-table
          :data="recordingInfo"
          height="250"
          border
          style="width: 100%"
        >
          <el-table-column
            prop="deviceInfo.name"
            label="设备名称"
            width="180"
          >
          </el-table-column>
          <el-table-column
            prop="value"
            label="抄表值"
            width="180"
          >
          </el-table-column>
          <el-table-column
            prop="unit"
            label="单位"
          >
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="抄表时间"
          >
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="meterRecordingDialog = false">取 消</el-button>
        <el-button type="primary" @click="meterRecordingDialog = false">确 定</el-button>
      </span>
    </el-dialog>

    <!--    抄表-->
    <el-dialog
      title="提示"
      :visible.sync="dialogMeterReading"
      width="40%"
    >
      <span slot="title">抄表</span>
      <div class="meterTable">
        <el-table :data="meterReadingData" border style="width: 100%">
          <el-table-column prop="value" label="抄表值"></el-table-column>
          <el-table-column prop="unit" label="单位"></el-table-column>
          <el-table-column prop="createTime" label="抄表时间"></el-table-column>
        </el-table>
      </div>
    </el-dialog>

    <!--    拉合闸记录列表-->
    <el-dialog
      title="拉合闸记录"
      :visible.sync="dialogClosing"
      width="50%"
    >
      <div class="Closing">
        <el-table :data="closingData" border style="width: 100%" height="250">
          <el-table-column prop="valveType" label="拉合闸类型"></el-table-column>
          <el-table-column prop="deviceId" label="电表设备id"></el-table-column>
          <el-table-column prop="operate" label="操作">
            <template slot-scope="scope">
              <span v-if="scope.row.operate==0">拉闸</span>
              <span v-if="scope.row.operate==1">合闸</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogClosing = false">取 消</el-button>
    <el-button type="primary" @click="dialogClosing = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  listAppsecret,
  getAppsecret,
  delAppsecret,
  addAppsecret,
  updateAppsecret,
  exportAppsecret,
  changeUserStatus,
  getDevies
} from '@/api/lock/sysAppsecret'
import { getDevices } from '@/api/brand/brand'
import {
  getDevice,
  copyTable,
  brake,
  selectRecord,
  getDeviceList,
  delDevice,
  updateDevice,
  addDevice,
  exportDevice,
  closingList
} from '@/api/device/device'
import { listBrand } from '@/api/brand/brand'
import { listDtu } from '@/api/dtu/dtu'
import { listData } from '@/api/system/dict/data'

export default {
  name: 'Appsecret',
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      //抄表记录显示开关弹窗
      meterRecordingDialog: false,
      dialogMeterReading: false,//抄表
      dialogClosing: false,//拉合闸开关弹窗
      //抄表记录
      recordingInfo: [],
      closingData: [],//拉合闸表格数据
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      appsecretList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      openView: false,
      // radio
      radio: undefined,
      // passwordType
      passwordType: 'password',
      //
      // 状态数据字典
      statusOptions: [],
      deviceId: [],
      meterReadingData: [],//抄表
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        appid: undefined,
        id: undefined,//设备id
        nodeid: undefined,//设备node id
        secret: undefined,
        totalCount: undefined,
        transferCount: undefined,
        ips: undefined,
        phone: undefined,
        addr: undefined,
        status: undefined
      },
      brakeStatusOption: [
        {
          value: 1,
          label: '开'

        },
        {
          value: 0,
          label: '关'

        }
      ],
      deviceTypeOption: [],//设备列表
      brandList: [],//品牌列表
      brandQuery: {
        pageNum: 1,
        pageSize: 10
      },
      brandOpen: false,//选择品牌弹窗
      //品牌下拉列表数据
      brandOption: [],

      DtuList: [],//Dtu列表
      DtuQuery: { //Dtu请求参数
        pageNum: 1,
        pageSize: 10
      },
      DtuOpen: false,//选择Dtu弹窗
      DtuOption: {//Dtu下拉列表数据

      },
      // 表单参数
      form: {
        brandId: undefined,
        dtuId: undefined
      },

      // 表单校验
      rules: {
        phone: [
          { required: true, message: '手机号码不能为空', trigger: 'blur' },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur'
          }
        ],
        name: [
          { required: true, message: '请输入用户名称', trigger: 'blur' }
        ],
        brandId: [
          { required: true, message: '请输入选择品牌', trigger: 'change' }
        ],
        dtuId: [
          { required: true, message: '请输入选择DTU', trigger: 'change' }
        ],
        slaves: [
          { required: true, message: '请输入通讯地址', trigger: 'blur' }
        ],
        nodeId: [
          { required: true, message: '请输入nodeId', trigger: 'blur' }
        ],

        deviceId: [
          { required: true, message: '请输入设备ID', trigger: 'blur' },
          {
            pattern: /^\d{6,10}$/,
            message: '请输入6-10数字设备ID',
            trigger: 'blur'
          }
        ],
        status: [
          { required: true, message: '请选择设备状态', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择设备类型', trigger: 'blur' }
        ],
        addr: [
          { required: true, message: '请输入地址', trigger: 'blur' }
        ],
        ips: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        totalCount: [
          { required: true, message: '请输入', trigger: 'blur' },
          {
            pattern: /^[0-9]+$/,
            message: '请输入数字',
            trigger: 'blur'
          }
        ]
      },
      icon2: 'el-icon-warning-outline',
      icon1: 'el-icon-view'
    }
  },
  created() {
    this.getList()
    this.getDevices()
    this.deviceType()
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true
      getDeviceList(this.queryParams).then(res => {
        // console.log(res)
        this.appsecretList = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        appid: undefined,
        secret: undefined,
        totalCount: undefined,
        transferCount: undefined,
        ips: undefined,
        phone: undefined,
        addr: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        status: '0'
      }
      this.resetForm('form')
    },
    //获取设备列表
    getDevices() {
      getDevices().then(res => {
        if (res.code == 200) {
          console.log(res)
        }
      })
    },
    deviceType() {
      listData({
        dictType: 'sys_device_type'
      }).then(res => {
        if (res.code == 200) {
          this.deviceTypeOption = res.rows
        }
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加设备'

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getDevice(id).then(response => {
        this.form = response.data
        this.form.brandId = Number(this.form.brandId)
        this.brandOption.push({
          label: response.data.deviceBrand.brandName,
          value: response.data.deviceBrand.id
        })
        this.open = true
        this.title = '修改设备'
      })
    },
    /** 提交按钮 */
    submitForm() {
      if (!this.form.brandId || !this.form.dtuId) {
        this.msgError('品牌/DUT不能为空')
        return false
      }
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDevice(this.form).then(response => {
              this.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addDevice(this.form).then(response => {
              this.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$confirm('是否确认删除 编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delDevice(ids)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有 数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return exportDevice(queryParams)
      }).then(response => {
        this.download(response.msg)
      })
    },

    closeForm() {
      this.$refs['form'].resetFields()
      this.brandOption = []
      this.open = false
    },

    //查询品牌
    getBrand() {
      this.brandOpen = true
      listBrand(this.brandQuery).then(res => {
        if (res.code == 200) {
          this.brandList = res
        }
      })
    },
    brandClose() { //关闭选择弹窗
      this.brandOption = []
    },
    brandCurrent(row) {//品牌选择
      if (row) {
        this.form.brandId = row.id
        this.brandOption.push({
          label: row.brandName,
          value: row.id
        })
        this.brandOpen = false
      }
    },

    getDtu() {//DTU查询
      this.DtuOpen = true
      listDtu(this.DtuQuery).then(res => {
        if (res.code == 200) {
          this.DtuList = res
        }
      })
    },
    DtuClose() { //关闭选择弹窗

    },
    DtuCurrent(row) {//DUT选择
      this.form.dtuId = row.nodeId
      this.DtuOption.label = row.name
      this.DtuOption.value = row.nodeId
      this.DtuOpen = false
    },

    switchGateClick(dtuId, nodeId) {
      console.log(dtuId)
    },

    switchGate(val, row) { //开关闸
      brake({
        dtuid: row.dtuId,
        nodeId: row.nodeId
      }).then(res => {
        this.getList()
      }).catch(err => {
        this.getList()
      })

    },

    // 用户状态修改
    handleStatusChange(row) {
      changeUserStatus(row.id, row.status).then(response => {
        this.$message({
          message: '操作成功',
          type: 'warning'
        })
      })
    },
    //查看按钮
    handleWatch(row) {
      getDevice(row.id).then(response => {
        this.form = response.data
        this.openView = true
        this.title = '电列数据'
      })
    },
    //抄表
    meterReadingRecording(row) {
      this.$confirm('确定要进行抄表?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        copyTable(row.id).then(res => {
          if (res.code == 200) {
            this.dialogMeterReading = true
            const data = res.data
            this.meterReadingData.push(data)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })

    },
    recording(row) {//抄表记录
      this.meterRecordingDialog = true
      selectRecord({
        deviceId: row.id
      }).then(res => {
        if (res.code == 200) {
          this.recordingInfo = res.data
        }
      })


    },
    //单个设备拉合闸记录s
    brakeRecord(row) {
      this.dialogClosing = true
      closingList(
        {  deviceId: row.id}
      ).then(res => {
        if (res.code == 200) {
          this.closingData = res.rows
        }
      })
    }

  }
}
</script>
